﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace TaskManagement.ModelLayer
{
    public class Workflow
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public DateTime? StartDate { get; set; }
        [Browsable(false)]
        public IList<Task> Tasks { get; set; }
        public int NumberOfTasks
        {
            get
            {
                return Tasks.Count;
            }
        }

        private decimal? completionPercentage;

        public string CompletionPercentage
        {
            get
            {
                if (completionPercentage == null)
                {
                    if (Tasks.Count != 0)
                    {
                        decimal totalTasks = Tasks.Count;
                        decimal completedTasks = Tasks.Count(t => t.Status.Equals("Completed"));
                        completionPercentage = (completedTasks / totalTasks) * 100;
                    }
                    else
                    {
                        completionPercentage = Tasks.Count;
                    }
                }
                return completionPercentage + "%";
            }
        }


        public Workflow()
        {
            this.Tasks = new List<Task>();
        }

    }
}
